package com.imooc.security.app;

import com.imooc.security.core.social.ImoocSpringSocialConfigurer;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * spring 容器在初始化之前和初始化之后都要经过的两个方法
 * 因为是在app模块中加入的所以只会在app模块中生效
 */
@Component
public class SpringSocialConfigurerPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (StringUtils.equals(beanName,"imoocSocialSecurityConfig")){
            ImoocSpringSocialConfigurer config = (ImoocSpringSocialConfigurer) bean;
            // 动态改变 注册地址
            config.signupUrl("/social/signUp");
            return config;

        }
        return bean;
    }
}
